#include <iostream>
#include <cassert>
#include <vector>
#include <algorithm>
#include <sstream>
#include <list>
#include <stack>
#include <queue>
#include <map>
using namespace std;

struct ListNode {
     int val;
     ListNode *next;
     ListNode() : val(0), next(nullptr) {}
     ListNode(int x) : val(x), next(nullptr) {}
     ListNode(int x, ListNode *next) : val(x), next(next) {}
};
//打印链表
void displayList(ListNode *p){
    while( p ){
        cout<< p->val ;
        p = p->next;
        if(p) cout<<"->";
    }
    cout<<endl;
}


//解决方案类
class Solution {
public:
    vector<int> intersection(vector<int>& nums1, vector<int>& nums2) {
        map<int,int> rt;
        vector<int> ans;
        int n1 = nums1.size() , n2 = nums2.size();
        if( n1 < 1 || n2 < 1) return ans;
        for(int i = 0;i< n1;++i) {
            if(rt.find(nums1[i]) == rt.end()) { //没找到数据
                rt.insert(pair<int,int>(nums1[i],0));
            }
        }
        for(int i = 0;i<n2 ;++i ){
            auto it = rt.find(nums2[i]) ;
            if( it == rt.end()) { //没有找到数据
                continue;
            } else { //找到数据
                if(it->second == 0 ){
                    it->second = 1;
                    ans.push_back(it->first);
                }     
            }
        }
        return ans;
    }
};
int main(){
    Solution sp;
    vector<int> a = {1,2,2,3}, b = {1,2,3,3} , c;
    c = sp.intersection(a,b);
    for( auto i : c ) cout<< i <<" "; cout<<endl; //遍历数组
    return 0;
}